<script setup lang="ts">
import { computed, ref } from "vue";
import { openExternal } from "@/framework/util/shell";
import MavenInstallGeneric from "./maven-install-generic.vue";
import MavenInstallHuaweicloud from "./maven-install-huaweicloud.vue";

defineOptions({ name: "maven-install-modal" });
const props = defineProps({
  open: { type: Boolean, default: false },
});
const emits = defineEmits({
  "update:open": (open: boolean) => true,
});

const modalOpen = computed({
  get: () => props.open,
  set: open => emits("update:open", open),
});
const activeKey = ref("generic");
const websites: Dict<string> = {
  generic: "https://maven.apache.org/",
  huaweicloud: "https://mirrors.huaweicloud.com/",
};

const openOfficialWebsite = () => {
  const website = websites[activeKey.value];
  if (website) {
    openExternal(website);
  }
};
</script>

<template>
  <a-modal v-model:open="modalOpen" title="安装" centered width="800px" destroy-on-close>
    <div style="height: 350px">
      <a-tabs v-model:active-key="activeKey" size="small" class="ant-tabs-full">
        <a-tab-pane key="generic" tab="官网/镜像">
          <maven-install-generic />
        </a-tab-pane>
        <a-tab-pane key="huaweicloud" tab="华为云">
          <maven-install-huaweicloud />
        </a-tab-pane>
      </a-tabs>
    </div>

    <template #footer>
      <div class="flex-sb">
        <a-space>
          <a-button type="link" @click="openOfficialWebsite">{{ websites[activeKey] }}</a-button>
        </a-space>
        <a-space>
          <a-button @click="modalOpen = false">取消</a-button>
        </a-space>
      </div>
    </template>
  </a-modal>
</template>
